package com.meixiang.activity.homes.service;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.activity.account.myAppointment.AppointmentDetailActivity;
import com.meixiang.activity.account.myShopper.OrderDetailActivity;
import com.meixiang.activity.homes.cosmeticTraining.CosmeticTrainingActivity;
import com.meixiang.activity.homes.shopping.CashierDeskActivity;
import com.meixiang.activity.homes.shopping.ShoppingHomeActivity;
import com.meixiang.entity.OrderResult;
import com.meixiang.main.BaseActivity;
import com.meixiang.main.MXApplication;
import com.meixiang.tool.Tool;
import com.meixiang.util.AbStrUtil;
import com.meixiang.view.TitleView;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 订单提交成功
 *
 * @author zys
 */
public class OrderSubmissionSuccessfulActivity extends BaseActivity {

    @Bind(R.id.title)
    TitleView title;
    @Bind(R.id.tv_installment_money)
    TextView tvInstallmentMoney;//分期付款金额
    @Bind(R.id.tv_order_submission_view_order)
    TextView tvOrderSubmissionViewOrder;//查看订单
    @Bind(R.id.tv_order_submission_back_home)
    TextView tvOrderSubmissionBackHome;//返回首页
    @Bind(R.id.tv_service_title)
    TextView mTvServiceTitle;

    private OrderResult mOrderResult;
    private HashMap<String, Class> gotoActivityMap;
    private String orderType;
    @SuppressWarnings("unchecked")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_order_submission_successful);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        if (intent != null) {
            mOrderResult = intent.getParcelableExtra(CashierDeskActivity.ORDER_RESULT);
            gotoActivityMap = (HashMap<String, Class>) intent.getSerializableExtra(CashierDeskActivity.GOTO_ACTIVITY);
        }
        super.onCreate(savedInstanceState);
        MXApplication.mApp.AddActivity(this);
    }

    @Override
    protected void initTitle() {
        title.setTitle("订单提交成功");
        title.setLeftImageButton(R.mipmap.back);
        title.showLeftButton(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MXApplication.mApp.RemoveActivity();
            }
        });
        title.setRightTextButton("完成");
        title.showRightButton(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               /* if (Tool.isFastDoubleClick()) return;
                if (gotoActivityMap == null || gotoActivityMap.get(CashierDeskActivity.GOTO_ACTIVITY) == null)
                    return;
                Intent intent = new Intent(OrderSubmissionSuccessfulActivity.this, gotoActivityMap.get(CashierDeskActivity.GOTO_ACTIVITY));
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);*/
                MXApplication.mApp.RemoveActivity();
            }
        });
    }

    @Override
    protected void initView() {
        orderType=getIntent().getStringExtra(CashierDeskActivity.ORDER_TYPE);
        if (mOrderResult == null) return;
        tvInstallmentMoney.setText("¥" + mOrderResult.getOrderAmount());
        String payCode=getIntent().getStringExtra("payCode");
        if (payCode.equals("ZFB")){
            mTvServiceTitle.setText("支付宝付款");
        }else if (payCode.equals("WX")){
            mTvServiceTitle.setText("微信付款");
        }else if (payCode.equals("YE")){
            mTvServiceTitle.setText("余额付款");
        }else if (payCode.equals("HYC")){
            mTvServiceTitle.setText("会员卡付款");
        }
    }

    @Override
    protected void setData() {
        Log.e("orderType",orderType+"---");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.tv_order_submission_view_order, R.id.tv_order_submission_back_home})
    public void onClick(View view) {
        if (Tool.isFastDoubleClick()) return;
        switch (view.getId()) {
            case R.id.tv_order_submission_view_order://查看订单
                Intent intent1 = new Intent();
                if (!AbStrUtil.isEmpty(orderType)&&orderType.equals("SC")){//商城 我的订单
                    //intent1.setClass(context, MyAllOrderActivity.class);
                    intent1.setClass(context, OrderDetailActivity.class);
                    intent1.putExtra("status", "待收货");
                }else{// 服务  我的预约
                    //intent1.setClass(context, MyAllAppointmentActivity.class);
                    intent1.setClass(context, AppointmentDetailActivity.class);
                    intent1.putExtra("status", "待使用");
                    if (!AbStrUtil.isEmpty(orderType)&&orderType.equals("FW")){
                        intent1.putExtra("typeId","1");
                    }else{
                        intent1.putExtra("typeId","2");
                    }

                }
                if (mOrderResult != null && !AbStrUtil.isEmpty(mOrderResult.getOrderId())) {
                    intent1.putExtra("orderId", mOrderResult.getOrderId());
                } else {
                    Tool.showTextToast(context, "未获取到商品id");
                    return;
                }
                startActivity(intent1);
                break;
            case R.id.tv_order_submission_back_home://返回首页  根据不同类型的订单返回至 商城首页  服务首页  培训首页
                Intent intent=new Intent();
                if (!AbStrUtil.isEmpty(orderType)&&orderType.equals("SC")){
                    intent.setClass(context, ShoppingHomeActivity.class);
                }else if (!AbStrUtil.isEmpty(orderType)&&orderType.equals("FW")){
                    intent.setClass(context, ServiceActivity.class);
                }else if (!AbStrUtil.isEmpty(orderType)&&orderType.equals("PX")){
                    intent.setClass(context, CosmeticTrainingActivity.class);
                }

                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
                break;
        }
        MXApplication.mApp.RemoveActivity();
    }

}
